package ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.fy.fyzf.R;
import com.fy.fyzf.base.BaseActivity;
import com.fy.fyzf.bean.AreaListBean;
import com.fy.fyzf.bean.BaseData;
import com.fy.fyzf.bean.HousesListBean;
import com.fy.fyzf.bean.PassengerDetailBean;
import com.fy.fyzf.bean.PassengerListBean;
import com.fy.fyzf.bean.SearchPassengerBean;
import com.fy.fyzf.presenter.PassengerPresnter;
import com.fy.fyzf.view.PassengerCallBack;
import com.fy.fyzf.view.SpacesItemDecoration;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import ui.adapter.HousingCollecAdapter;
import ui.adapter.MatchHousingAdapter;

public class HousingCollectActivity extends BaseActivity<PassengerPresnter> implements PassengerCallBack {

    @BindView(R.id.recycleView)
    RecyclerView recycleView;
    @BindView(R.id.tv_save)
    TextView tvSave;
    private HousingCollecAdapter housesListAdapter;

    @Override
    protected PassengerPresnter createPresenter() {
        return new PassengerPresnter(this);
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_housing_collect;
    }

    @Override
    public void initView() {
        super.initView();
        setTitleName("收藏房源");

        housesListAdapter = new HousingCollecAdapter(this, 2, true);
        recycleView.setLayoutManager(new LinearLayoutManager(this));
        recycleView.addItemDecoration(new SpacesItemDecoration(16));
        recycleView.setAdapter(housesListAdapter);

        housesListAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {

            private Intent intentCallBack;

            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                List<HousesListBean.ListBean> listBeans = adapter.getData();
                if (listBeans.get(position).isCheck()) {
                    listBeans.get(position).setCheck(false);
                    listBeans.get(position).setTakeLook(null);
                    housesListAdapter.selectMap.remove(position);
                } else {
                    listBeans.get(position).setTakeLook("");
                    housesListAdapter.selectMap.put(position, true);
                    listBeans.get(position).setCheck(true);
                }
                housesListAdapter.notifyDataSetChanged();
            }
        });
    }

    @Override
    public void initData() {
        super.initData();
        int id = getIntent().getIntExtra("id", 0);
        SearchPassengerBean searchPassengerBean = new SearchPassengerBean();
        searchPassengerBean.setPageNum(1);
        searchPassengerBean.setPageSize(100);
        searchPassengerBean.setCustomerId(id);

        mPresenter.getCollectHousing(searchPassengerBean);

    }

    @Override
    public void getPassengerListSuccess(PassengerListBean passengerListBean) {

    }

    @Override
    public void getPassengerDetailSuccess(PassengerDetailBean passengerDetailBean) {

    }

    @Override
    public void getCollectHousingSuccess(HousesListBean housesListBean) {
        if (housesListBean.getList() == null || housesListBean.getList().size() == 0) {
            housesListAdapter.setEmptyView(R.layout.layout_nodata_common, recycleView);
        }
        housesListAdapter.setNewData(housesListBean.getList());
    }

    @Override
    public void getMatchHousingSuccess(HousesListBean housesListBean) {

    }

    @Override
    public void getRecommendHousingSuccess(HousesListBean housesListBean) {

    }

    @Override
    public void collectHousingSuccess(BaseData baseData, int i) {

    }

    @Override
    public void removecollectHousingSuccess(BaseData baseData, int i) {

    }

    @Override
    public void AddPassengerSourceSuccess(BaseData baseData) {

    }

    @Override
    public void getSiteListSuccess(List<AreaListBean> areaListBeans) {

    }

    @Override
    public void editPassengerSuccess(BaseData baseData) {

    }


    @OnClick({R.id.recycleView, R.id.tv_save})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.recycleView:
                break;
            case R.id.tv_save:
                setResult(10002, new Intent().putExtra("data", housesListAdapter.getSelectedItem()));
                finish();
                break;
        }
    }
}